import React, { useState, useEffect } from 'react'
import { reqgetbanner, reqgetindexgoods, reqgetnew, reqgetseckill } from '../../http/api'
import Banner from './components/banner/Banner'
import News from './components/news/news'
import Seckill from "./components/seckill/seckill"
import Goods from "./components/goods/goods"
const Home = () => {

  const [banner, setBanner] = useState([])
  const [news, setNews] = useState([])
  const [seckill, setSeckill] = useState([])
  const [goods, setGoods] = useState([])
  const [n, setn] = useState(0)

  useEffect(() => {
    //  请求轮播数据
    reqgetbanner().then(res => {
      setBanner(res.data.list)
    })
    // 新人专享
    reqgetnew().then(res => {
      setNews(res.data.list)
    })
    //  秒杀
    reqgetseckill().then(res => {
      setSeckill(res.data.list)
    })
    // 首页商品
    reqgetindexgoods().then(res => {
      setGoods(res.data.list)
    })
  }, [])

  return (
    <div>
      {/* 轮播 */}
      <Banner banner={banner}></Banner>
      {/* 新人专享 */}
      <News news={news}></News>
      {/* {秒杀} */}
      <Seckill seckill={seckill}></Seckill>
      {/* 首页商品 */}
      <Goods goods={goods} n={n} onchangen={n=>setn(n)}></Goods>
    </div>
  )
}

export default Home